﻿using ApplicationBase.Core.Cache;
using ApplicationBase.Core.Context;
using ApplicationBase.Core.Service.Identity;
using ApplicationBase.Core.Utils;
using Autofac;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Memory;

namespace ApplicationBase.Core
{
    public class BaseModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            //常用服务上下文（获取用户身份信息/生成雪花Id/当前时间等）
            builder.RegisterType<ServiceContext>().As<IServiceContext>().SingleInstance();
            builder.RegisterType<IdentityService>().As<IIdentityService>().SingleInstance();
            builder.RegisterType<UTCClock>().As<IClock>().SingleInstance();
            builder.RegisterType<SnowflakeWorker>().As<ISnowflakeWorker>().SingleInstance();
            builder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
            builder.RegisterType<MemoryCache>().As<IMemoryCache>().SingleInstance();
            builder.RegisterType<MemoryCacheService>().As<ICacheService>().SingleInstance();
        }
    }
}
